package com.pay.sdk.example;

import java.net.InetAddress;
import java.text.SimpleDateFormat;
import java.util.Date;

import com.pay.sdk.service.channel1.ChannelOnePay;
/**
 * 通道1 扫码 条码 H5代码示例
 * @author Administrator
 *
 */
public class Channel1Example {

	public static void main(String[] args) {
        System.out.println("==重要== 调用任何API前，请先配置Configure类");
      //使用测试环境，生产上使用请设置为false
//        alipayScanPayExample();
//        wechatScanPayExample();
//        wechatJsPayExample();
//        payQueryExample();
        liquidationExample();
//        liquidationQueryExample();
//        queryBalanceExample();
//        bankCodeQueryExample();
//        appPayExample();//
    }
	
	
	 /**
     * 支付宝扫码支付
     * @throws  
     */
    public static void alipayScanPayExample(){
    	try {
    		String out_trade_no = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
        	String total_fee = "60"; //单位分
        	String body = "支付宝扫码测试";
        	String notify_url = "http://www.baidu.com";
        	String device_info = "PC_"+ InetAddress.getLocalHost().getHostAddress();
        	String result = ChannelOnePay.alipayScanPay(out_trade_no, total_fee, body, device_info, notify_url);
        	System.out.println("支付宝扫码支付："+result);
		} catch (Exception e) {
			e.printStackTrace();
		}
    }
    
    
    /**
     * 微信扫码支付
     * @throws  
     */
    public static void wechatScanPayExample(){
    	try {
    		String out_trade_no = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
        	String total_fee = "1"; //单位分
        	String body = "微信扫码测试";
        	String device_info = "PC";
        	String notify_url = "http://www.baidu.com";
        	String result = ChannelOnePay.wechatScanPay(out_trade_no, total_fee, body, device_info,notify_url);
        	System.out.println("微信扫码支付："+result);
		} catch (Exception e) {
			e.printStackTrace();
		}
    }
    
    /**
     * 微信公众号支付
     * @throws  
     */
    public static void wechatJsPayExample(){
    	try {
    		String out_trade_no = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
        	String total_fee = "60"; //单位分
        	String body = "微信扫码测试";
        	String sub_openid = "oM4YVs9mpmBAFbzORjXUGeqkXkKg";
        	String notify_url = "http://www.baidu.com";
        	String device_info = "PC";
        	String result = ChannelOnePay.wechatJsPay(out_trade_no, total_fee, body, sub_openid, device_info, notify_url);
        	System.out.println("微信扫码支付："+result);
		} catch (Exception e) {
			e.printStackTrace();
		}
    }
    
    
    /**
     * 支付结果查询接口
     * @throws  
     */
    public static void payQueryExample(){
    	try {
    		String out_trade_no = "20161224212801";
        	String result = ChannelOnePay.payQuery(out_trade_no);
        	System.out.println("支付结果查询："+result);
		} catch (Exception e) {
			e.printStackTrace();
		}
    }
    
    
   
    
    
   
    
    
    /**
     * 单笔实时代付接口
     * @param merchant_no 商户号
     * @param user_order_no 商户订单号
     * @param amount 金额 （元）
     * @param account_no 账号
     * @param account_name 帐户名
     * @param bank_code 银行行号
     * @param acct_type 对方账户类型：0-储蓄卡;1-信用卡;2-企业账户
     * @param usage 转账用途
     * @return
     * 		测试卡号：622909443442019514
			银行行号： 309391000011
			账户类型：储蓄卡
			姓名：惠举
			
			测试卡号：4512906000064106
			银行行号： 309391000011
			账户类型：信用卡
			姓名：胡兰
			
			测试卡号：6222801234567888953
			银行行号：105100000017
			账户类型：储蓄卡
			姓名：张三
			
			测试账号：117010100100316139
			银行行号：309391000011
			账户类型：对公账户
			企业名称：X的测试账户

     */
    public static void liquidationExample(){
    	try {
    		String user_order_no = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());;
    		String amount = "0.1";
    		String account_no = "622909443442019514";
    		String account_name = "惠举";
    		String bank_code = "309391000011";
    		String acct_type = "0";
    		String usage = "测试";
//    		String account_no = "6228480089507xxxxxx2";
//    		String account_name = "杨xxxx";
//    		String bank_code = "103100000026";//农行
//    		String acct_type = "0";
//    		String usage = "正式账号测试";
        	String result = ChannelOnePay.liquidation(user_order_no, amount, account_no,account_name,bank_code,acct_type,usage);
        	System.out.println("单笔实时代付："+result);
		} catch (Exception e) {
			e.printStackTrace();
		}
    }
    
    
    //单笔代付查询接口
    public static void liquidationQueryExample(){
    	try {
    		String order_no = "584482306573213696";
    		String user_order_no = "";//20170105162038
        	String result = ChannelOnePay.liquidationQuery(order_no,user_order_no);
        	System.out.println("单笔代付查询："+result);
		} catch (Exception e) {
			e.printStackTrace();
		}
    }
    
    
    //企业账户余额信息查询
    public static void queryBalanceExample(){
    	try {
        	String result = ChannelOnePay.queryBalance();
        	System.out.println("企业账户余额信息查询："+result);
		} catch (Exception e) {
			e.printStackTrace();
		}
    }
    
    
    //银行代码查询
    public static void bankCodeQueryExample(){
    	try {
        	String result = ChannelOnePay.bankCodeQuery();
        	System.out.println("企业账户余额信息查询："+result);
		} catch (Exception e) {
			e.printStackTrace();
		}
    }
    


    //app支付
    public static void appPayExample(){
    	try {
    		String out_trade_no = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
        	String total_fee = "1"; //单位分
        	String body = "微信app测试";
        	String notify_url = "http://paytest.shopping98.com/pay/apiNotify.shtml";
        	String device_info = "APP";
        	String result = ChannelOnePay.appPay(out_trade_no, total_fee, body, device_info, notify_url);
        	System.out.println("app支付："+result);
		} catch (Exception e) {
			e.printStackTrace();
		}
    }
	
}
